<template>
  <div class="questionDetail"  v-if="servDetail">
    <div class="questionDetailHeader">
      <img src="../../assets/image/goBack.png" @click="goBack"/>
      <p>问题详情</p>
    </div>
    <div class="questionBox">
        <div class="imgBox">
          <img :src="servDetail.SERVDETAIL_PHOTO" alt="">
        </div>
        <p>{{servDetail.SERVDETAIL_NAME}}</p>
        <img class="sanjiaoImg" src="../../assets/image/question/sanjiao.jpg" alt="">
    </div>
    <div class="questionContent">
      <img class="questionImg" src="../../assets/image/question/question.png" alt="">
      <div class="headerImg">
        <img :src="questionDate.SPICT_USERS_PATH" alt="">
      </div>
      <div class="contentRight">
        <p class="myName">{{questionDate.USER_NAME|fiterPhone}}<span class="qData">{{questionDate.MESSAGE_TIME|filterTime5}}</span></p>
        <p class="myQuestion">{{questionDate.MESSAGE}}</p>
      </div>
    </div>
    <div class="line"></div>
    <div class="questionResponse" v-if="answerList.length>0">
      <img class="answerImg" src="../../assets/image/question/answer.png" alt="">
      <ul class="answerList" >
        <li v-for="item in answerList">
          <div class="headerImg">
            <img :src="item.SPICT_USERS_PATH" alt="" class="header1">
          </div>
          <div class="contentRight">
            <p class="myName">{{item.USER_NAME|fiterPhone}}<span class="qData">{{item.ANSWER_TIME|filterTime5}}</span></p>
            <p class="myQuestion">{{item.MESSAGE}}</p>
            <div class="imgList" >
              <img v-for="img in item.PHOTO_LIST" :src="img.PHOTO_NAME" alt="">
            </div>
          </div>
        </li>
      </ul>
    </div>
    <div class="noAnswer" v-if="answerList.length==0">
      <img src="../../assets/image/question/noQuestion.png" alt="">
      <p>暂时没有人回答~</p>
    </div>
    <div class="btnBox" v-if="!isBuy">
       <img src="../../assets/image/question/tip.png">
       <div class="answerBtn1" >我来回答</div>
    </div>
    <div class="btnBox" v-if="isBuy">
      <div class="answerBtn" @click="doAnswer">我来回答</div>
    </div>
     <confirm v-model="confirmVisible" title="提示" @on-confirm="hide">
      <p style="text-align:center;">不能回答自己的问题哦</p>
    </confirm>
  </div>
</template>
<script>
/*问题详情*/
import {XHeader,Confirm} from 'vux';
import { setCookie, getCookie } from '../../util/commonUtils';
export default {
  name:"questionDetail",
  // 数据
  data(){

    return{
    	userId:'',
      questionId:this.$route.params.id,//问题Id;
      questionDate:'',//问题数据
      answerList:'',//回答列表
      servDetail:'',//商品详情
      hasAnswer:false,
      isBuy:false,//是否购买过该商品
      isMyself:false,
      confirmVisible:false,
    }
  },
  // 计算属性
  computed:{

  },
  // 创建（实例创建完成）
  created(){
    this.$vux.loading.show({
      text: ''
    });
    this.userId=getCookie('loginkey');

    let obj={QUESTION_ID:this.questionId};

    this.$fetchPost("serviceDetailQA/getServiceDetailQADetail",{USER_ID:this.userId,QUESTION_ID:this.questionId}).then(res=>{
       // console.log(res)
        this.$vux.loading.hide();
        if (res.USER_STATUS){
           this.isBuy=true;
        }
        if (res.IS_MYSELF){
           this.isMyself=true;
        }
        this.questionDate=res.QUESTION_DATE;
        this.answerList = res.ANSWER_LIST;
        this.servDetail = res.SERVDETAIL_LIST;
        sessionStorage.setItem('quser',this.questionDate.USER_NAME);
        sessionStorage.setItem('qdate',this.questionDate.MESSAGE_TIME);
        sessionStorage.setItem('qmess',this.questionDate.MESSAGE);
    },err=>{
      console.log(err)
    })
  },
  // el被创建，并挂载到实例上
  mounted(){

  },
  // 方法（实例中的方法）-----------
  methods:{
    hide(){
      this.confirmVisible=false
    },
    goBack(){
      this.$router.go(-1)
      },

    doAnswer(){
      if (this.isMyself) {
        this.confirmVisible=true;
        return;
      }
      this.$router.push('/doAnswer/'+this.questionId)
    }

  },

  // 子组件
  components:{
    XHeader,
    Confirm
  }
}
</script>
<!--当前页面的样式 -->
<style lang="less" scoped>
  .questionDetail{
    width: 7.5rem;
    height: 100%;
    overflow: hidden;
    background: #fff;
    padding-bottom: 1.3rem;
    overflow: auto;
    .questionDetailHeader{
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      background: #fff;
      z-index: 9;
      height:0.8rem;
      line-height:0.8rem;
      font-size:0.33rem;

      color:#222222;
      img{
        position: absolute;
        left: 0.22rem;
        bottom: 0.25rem;
        height: 0.38rem;
      }
    }
    .questionBox{
      margin-top: 0.8rem;
      position: relative;
      height: 1.5rem;
      background: #ffffff;
      .sanjiaoImg{
        position: absolute;
        bottom: 0;
        left:0.72rem;
        width: 0.25rem;
        height:0.12rem;
        z-index: 2;
      }
      .imgBox{
        position: absolute;
        width: 0.9rem;
        height: 0.9rem;
        left: 0.4rem;
        top:0.3rem;
        img{
          display: block;
          width:0.9rem;
          height: 0.9rem;
        }
      }
      p{
        padding-left:1.5rem;
        font-size:0.3rem;
        color:#222222;
        line-height:1.5rem;
        padding-right: 0.2rem;
        height: 1.5rem;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        text-align: left;
      }
    }
    .questionContent{
      position:relative;
      .questionImg{
        position: absolute;
        top:-0.03rem;
        left: 0;
        width: 0.4rem;
        height:0.42rem;

      }
      .headerImg{
        img{
          position: absolute;
          left:0.3rem;
          top:0.3rem;
          width: 0.6rem;
          height:0.6rem;
          border-radius: 50%;
        }
      }
      .contentRight{
        padding-left:1.1rem;
        text-align:left;
        padding-top:0.46rem;
        padding-bottom:0.3rem;
        .myName{
          font-size: 0.27rem;
          color:#666;
          margin-bottom:0.38rem;
          .qData{
            float: right;
            font-size:0.19rem;
            color:#999999;
            margin-right: 0.3rem;
          }
        }
        .myQuestion{
          font-size: 0.29rem;
          color:#222222;
          padding-right: 0.3rem;
        }
      }
    }
    .line{
      background: #f5f5f5;
      width:100%;
      height:0.2rem;
    }
  }
  .noAnswer{
    position: absolute;
    width: 100%;
    padding-top:1.6rem;

    font-size:0.29rem;
    color:#999999;
    img{
      position: absolute;
      top: 2.8rem;
      left: 50%;
      margin-left: -0.85rem;
      width: 1.7rem;
    }
    p{

      position: absolute;
      top:4rem;
      width: 100%;
    }
  }
  .questionResponse{
    position:relative;
    .answerImg{
      position: absolute;
      top:-0.03rem;
      left: 0;
      width: 0.4rem;
      height:0.42rem;
    }
    .answerList{
      li{
        position:relative;
        .headerImg{
          .header1{
            position: absolute;
            left:0.3rem;
            top:0.3rem;
            width: 0.6rem;
            height:0.6rem;
            border-radius: 50%;
          }
        }
        .contentRight{
          padding-left:1.1rem;
          text-align:left;
          padding-top:0.52rem;
          padding-bottom:0.3rem;
          .myName{
            font-size: 0.27rem;
            color:#666;
            margin-bottom:0.38rem;
            .qData{
              float: right;
              font-size:0.19rem;
              color:#999999;
              margin-right: 0.3rem;
            }
          }
          .myQuestion{
            font-size: 0.29rem;
            color:#222222;
            padding-right: 0.3rem;
          }
          .imgList{
            overflow:hidden;
            
            img{
              margin-top: 0.1rem;
              width: 1.49rem;
              height:1.49rem;
              float: left;
              border-radius:0.05rem;
              margin-right:0.2rem
            }
          }
        }
      }
    }
  }
  .btnBox{
    position: absolute;
    z-index: 9;
    width:100%;
    height: 1.3rem;
    bottom: 0;
    left:0;
    background: #fff;

    .answerBtn{
      margin: 0.2rem auto;
      height: 0.7rem;
      width: 2.8rem;
      border-radius: 0.35rem;
      background:#F22E2E;
      line-height: 0.7rem;
      color: #ffffff;
      font-size: 0.29rem;
    }
    img{
      position: absolute;
      width: 4rem;
      left: 50%;
      margin-left: -2rem;
      top: -0.8rem;
    }
    .answerBtn1{
      margin: 0.2rem auto;
      height: 0.7rem;
      width: 2.8rem;
      border-radius: 0.35rem;
      background:#e5e5e5;
      line-height: 0.7rem;
      color: #999999;
      font-size: 0.29rem;
    }
  }
  .answerList li:after{
    content: '';
    position: absolute;
    width: 6.4rem;
    left: 1.1rem;
    bottom: 0;
    height: 1px;
    background: #dddddd;
  }
  .questionBox:after{
    content: '';
    position: absolute;
    width: 6.9rem;
    left: 0.3rem;
    -webkit-transform: scaleY(0.5);
    transform: scaleY(0.5);
    bottom: 0;
    height: 1px;
    background: #dddddd;
  }
  .questionDetailHeader:after{
    content: '';
    position: absolute;
    bottom: 0 ;
    left:0 ;
    width: 100%;
    -webkit-transform: scaleY(0.5);
    transform: scaleY(0.5);
    height: 1px;
    background: #dddddd;
  }
  [v-cloak] {
    display: none!important;
  }
</style>
